<?php
include_once "wxstore/wxBizMsgCrypt.php";
$wxData = include_once "wxstore/wxConfig.php";
// 第三方发送消息给公众平台
$encodingAesKey = $wxData['SecretKey'];
$token = $wxData['Token'];
$appId = $wxData['AppId'];
$appSecret = $wxData['AppSecret'];

$timeStamp = empty ( $_GET ['timestamp'] ) ? '' : trim ( $_GET ['timestamp'] );  
$nonce = empty ( $_GET ['nonce'] ) ? '' : trim ( $_GET ['nonce'] );  
$msg_sign = empty ( $_GET ['msg_signature'] ) ? "" : trim ( $_GET ['msg_signature'] );  
$encryptMsg = file_get_contents ( 'php://input' );  

$pc = new WXBizMsgCrypt ( $token, $encodingAesKey, $appId ); 

include_once "wxstore/wxHelper.php";
$helper = new wxHelper();
// 第三方收到公众号平台发送的消息
$msg = '';
$errCode = $pc->decryptMsg ( $msg_sign, $timeStamp, $nonce, $encryptMsg, $msg );

if ($errCode == 0) {
	$data = $helper->xmlToArr ( $msg );
	$filedata['component_verify_ticket'] = $data['ComponentVerifyTicket'];
	//如果是获取ticket
	if(!empty($data['ComponentVerifyTicket']))
	{
		$helper->set_php_file(dirname(__FILE__)."/wxstore/static/component_verify_ticket.php", json_encode($filedata));
	}
	//如果是取消授权
	if($data['InfoType'] == 'unauthorized')
	{
		define('IN_ECS', true);
		include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/init.php';
		$db->query("UPDATE ".$ecs->table('wxauthorizer')." SET authorizer_status=0 WHERE authorizer_appid='".$data['AuthorizerAppid']."' ");
	}
	echo 'success';
} else {
	echo $errCode;
}

?>